package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/jsonparam")
public class ParamJsonController {
    @RequestMapping("/json1")
    @ResponseBody
    public String json1(@RequestBody List<String> list){
        System.out.println(list);
        return "{info:hello}";
    }
    @RequestMapping("/json2")
    @ResponseBody
    public String json2(@RequestBody List<String> likes){
        System.out.println("list common(json)参数传递 list ==> "+likes);
        return "{'module':'list common for json param'}";
    }
    @RequestMapping("/pojo3")
    @ResponseBody
    public String pojo3(@RequestBody User user){
        System.out.println("pojo(json)参数传递 user ==> "+user);
        return "{'module':'pojo for json param'}";
    }
    @RequestMapping("/pojo4")
    @ResponseBody
    public String pojo4(@RequestBody List<User> list){
        System.out.println("list pojo(json)参数传递 list ==> "+list);
        return "{'module':'list pojo for json param'}";
    }

    @RequestMapping("/resp1")
    @ResponseBody
    public User response1(){
        System.out.println("response1");
        List<User> list = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setAge(16);
        user.setName("lisi");
        list.add(user);
        list.add(user);
        list.add(user);
        return user;
    }


}
